<script>
import { mapState } from 'vuex'
import { config, formConfig, column } from './formConfig.js'
import SearchManage from '@/components/basic/SearchManage.vue'
import { requestApi, getEigApi } from '@/requset/api'
import { deepClone } from '@/plugins/clone.js'

export default {
    extends: SearchManage,
    data() {
        return {
            table_title: '备件',
            url: 'spare',
            actions: [
                {
                    label: '添加',
                    icon: 'el-icon-folder-add',
                    click: () => {
                        this.handleAdd()
                    },
                    if: () => this.operate,
                },
            ],
            dialog: {
                labelWidth: '100px',
                config: [],
                form: {},
                title: '',
            },
            queryForm: {
                page: 1,
                size: 20,
                name: null,
            },
            queryFormC: {
                page: 1,
                size: 20,
                name: null,
            },
            baseForm: {},
        }
    },
    computed: {
        ...mapState('backstage', ['backstageData', 'eigenvalueTags', 'sensorType']),
        tags() {
            if (this.pagination.total !== undefined) {
                return [{ title: '总数', num: this.pagination.total }, { title: '离线数', num: this.stat.un }, null, { title: '在线数', num: this.stat.on }]
            } else return []
        },
    },
    methods: {
        searchBtn() {
            this.getlist()
        },
        to(data) {
            return data
        },
        BeforeAdd() {
            this.dialog.config = config
        },
        BeforeEdit() {
            this.dialog.config = config
        },
        getlist() {
            this.loading = true
            requestApi('post', this.url + `/getlist`, this.queryForm).then((res) => {
                this.tableData = res.data.data
                this.pagination = res.data.pagination
                if (res.data.stat) {
                    this.stat = res.data.stat
                }
                this.pagination = res.data.pagination
                this.loading = false
            })
        },
    },
    created() {
        this.getlist()
        this.dialog.config = config
        column[column.length - 1].buttons = [
            {
                text: '编辑',
                click: (val) => {
                    this.handleEdit(val)
                },
                icon: 'el-icon-edit',
            },
            {
                text: '删除',
                click: (val) => {
                    this.delete(val)
                },
                icon: 'el-icon-delete',
            },
        ]
        column[column.length - 1].if = this.operate
        this.tableColumn = column
        this.formConfig = formConfig
    },
}
</script>
